﻿// See https://aka.ms/new-console-template for more information
public class Program {
    public static void Main(string[] args) {
        MassageFactoryProducer factoryProducer = new MassageFactoryProducer();
        User usera = new User(1,"A");
        User userb = new User(2,"B");
        usera.AddFriend(userb);
        userb.AddFriend(usera);
        ChatBox? chatBox = usera.GetChatBox("B");
        string? type, data;
        while (true) {
            Console.WriteLine("输入消息类型:text/pic/music 或输入quit退出");
            type = Console.ReadLine();
            if (string.IsNullOrEmpty(type)) continue;
            if (type == "quit") break;
            AbstractMassageFactory? factory = factoryProducer.GetMassageFactory(type);
            if (factory == null) {
                Console.WriteLine("未知的消息类型!");
                continue;
            } else {
                while (true) {
                    Console.WriteLine("输入消息:");
                    data = Console.ReadLine();
                    if (string.IsNullOrEmpty(data)) continue;
                    var message = factory.GetMessage(data);
                    if (message != null) {
                        chatBox.AddMessage(message);
                        chatBox.Display();
                        break;
                    }
                }
            }
        }
    }
}
